'use strict';
var _typeof = 'function' == typeof Symbol && 'symbol' == typeof Symbol.iterator ? function(a) {
		return typeof a
	} : function(a) {
		return a && 'function' == typeof Symbol && a.constructor === Symbol && a !== Symbol.prototype ? 'symbol' : typeof a
	},
	_createClass = function() {
		function a(b, c) {
			for (var f, e = 0; e < c.length; e++) f = c[e], f.enumerable = f.enumerable || !1, f.configurable = !0, 'value' in f &&
				(f.writable = !0), Object.defineProperty(b, f.key, f)
		}
		return function(b, c, e) {
			return c && a(b.prototype, c), e && a(b, e), b
		}
	}(),
	_calendar = require('./calendar.js'),
	_calendar2 = _interopRequireDefault(_calendar);
Object.defineProperty(exports, '__esModule', {
	value: !0
});

function _interopRequireDefault(a) {
	return a && a.__esModule ? a : {
		default: a
	}
}

function _classCallCheck(a, b) {
	if (!(a instanceof b)) throw new TypeError('Cannot call a class as a function')
}
var Calendar = function() {
	function a() {
		var b = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {},
			c = b.date,
			e = b.selected,
			f = b.startDate,
			g = b.endDate,
			h = b.range;
		_classCallCheck(this, a), this.date = this.getDate(new Date), this.selected = e || [], this.startDate = f, this.endDate =
			g, this.range = h, this.cleanMultipleStatus(), this.weeks = {}
	}
	return _createClass(a, [{
		key: 'setDate',
		value: function setDate(b) {
			this.selectDate = this.getDate(b), this._getWeek(this.selectDate.fullDate)
		}
	}, {
		key: 'cleanMultipleStatus',
		value: function cleanMultipleStatus() {
			this.multipleStatus = {
				before: '',
				after: '',
				data: []
			}
		}
	}, {
		key: 'resetSatrtDate',
		value: function resetSatrtDate(b) {
			this.startDate = b
		}
	}, {
		key: 'resetEndDate',
		value: function resetEndDate(b) {
			this.endDate = b
		}
	}, {
		key: 'getDate',
		value: function getDate(b) {
			var c = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : 0,
				e = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : 'day';
			b || (b = new Date), 'object' !== ('undefined' == typeof b ? 'undefined' : _typeof(b)) && (b = b.replace(/-/g,
				'/'));
				if(!/\d{4}\/\d{2}\/\d{2}/.test(b)) {
					b += '/01';
				}
			var f = new Date(b);
			'day' === e ? f.setDate(f.getDate() + c) : 'month' === e ? 31 === f.getDate() ? f.setDate(f.getDate() + c) : f.setMonth(
				f.getMonth() + c) : 'year' === e ? f.setFullYear(f.getFullYear() + c) : void 0;
			var g = f.getFullYear(),
				h = 10 > f.getMonth() + 1 ? '0' + (f.getMonth() + 1) : f.getMonth() + 1,
				j = 10 > f.getDate() ? '0' + f.getDate() : f.getDate();
			return {
				fullDate: g + '-' + h + '-' + j,
				year: g,
				month: h,
				date: j,
				day: f.getDay()
			}
		}
	}, {
		key: '_getLastMonthDays',
		value: function _getLastMonthDays(b, c) {
			for (var g, e = [], f = b; 0 < f; f--) g = new Date(c.year, c.month - 1, -f + 1).getDate(), e.push({
				date: g,
				month: c.month - 1,
				lunar: this.getlunar(c.year, c.month - 1, g),
				disable: !0
			});
			return e
		}
	}, {
		key: '_currentMonthDys',
		value: function _currentMonthDys(b, c) {
			for (var e = this, f = [], g = this.date.fullDate, h = function _loop(j) {
					var n = c.year + '-' + (10 > c.month ? c.month : c.month) + '-' + (10 > j ? '0' + j : j),
						p = e.selected && e.selected.find(function(w) {
							if (e.dateEqual(n, w.date)) return w
						}),
						q = !0,
						r = !0;
					if (e.startDate) {
						var w = e.dateCompare(e.startDate, g);
						q = e.dateCompare(w ? e.startDate : g, n)
					}
					if (e.endDate) {
						var w = e.dateCompare(g, e.endDate);
						r = e.dateCompare(n, w ? e.endDate : g)
					}
					var s = e.multipleStatus.data,
						t = !1,
						u = -1;
					e.range && (s && (u = s.findIndex(function(w) {
						return e.dateEqual(w, n)
					})), -1 !== u && (t = !0));
					var v = {
						fullDate: n,
						year: c.year,
						date: j,
						multiple: !!e.range && t,
						beforeMultiple: e.dateEqual(e.multipleStatus.before, n),
						afterMultiple: e.dateEqual(e.multipleStatus.after, n),
						month: c.month,
						lunar: e.getlunar(c.year, c.month, j),
						disable: !q || !r,
						isDay: g === n
					};
					p && (v.extraInfo = p), f.push(v)
				}, j = 1; j <= b; j++) h(j);
			return f
		}
	}, {
		key: '_getNextMonthDays',
		value: function _getNextMonthDays(b, c) {
			for (var e = [], f = 1; f < b + 1; f++) e.push({
				date: f,
				month: +c.month + 1,
				lunar: this.getlunar(c.year, +c.month + 1, f),
				disable: !0
			});
			return e
		}
	}, {
		key: 'getInfo',
		value: function getInfo(b) {
			var c = this;
			b || (b = new Date);
			var e = this.canlender.find(function(f) {
				return f.fullDate === c.getDate(b).fullDate
			});
			return e
		}
	}, {
		key: 'dateCompare',
		value: function dateCompare(b, c) {
			return b = new Date(b.replace('-', '/').replace('-', '/')), c = new Date(c.replace('-', '/').replace('-', '/')),
				!!(b <= c)
		}
	}, {
		key: 'dateEqual',
		value: function dateEqual(b, c) {
			return b = new Date(b.replace('-', '/').replace('-', '/')), c = new Date(c.replace('-', '/').replace('-', '/')),
				0 == b.getTime() - c.getTime()
		}
	}, {
		key: 'geDateAll',
		value: function geDateAll(b, c) {
			var e = [],
				f = b.split('-'),
				g = c.split('-'),
				h = new Date;
			h.setFullYear(f[0], f[1] - 1, f[2]);
			var j = new Date;
			j.setFullYear(g[0], g[1] - 1, g[2]);
			for (var l = h.getTime() - 86400000, n = j.getTime() - 86400000, o = l; o <= n;) o += 86400000, e.push(this.getDate(
				new Date(parseInt(o))).fullDate);
			return e
		}
	}, {
		key: 'getlunar',
		value: function getlunar(b, c, e) {
			return _calendar2.default.solar2lunar(b, c, e)
		}
	}, {
		key: 'setSelectInfo',
		value: function setSelectInfo(b, c) {
			this.selected = c, this._getWeek(b)
		}
	}, {
		key: 'setMultiple',
		value: function setMultiple(b) {
			var c = this.multipleStatus,
				e = c.before,
				f = c.after;
			this.range && (e && f ? (this.multipleStatus.before = '', this.multipleStatus.after = '', this.multipleStatus.data = []) :
				e ? (this.multipleStatus.after = b, this.multipleStatus.data = this.dateCompare(this.multipleStatus.before,
					this.multipleStatus.after) ? this.geDateAll(this.multipleStatus.before, this.multipleStatus.after) : this.geDateAll(
					this.multipleStatus.after, this.multipleStatus.before)) : this.multipleStatus.before = b, this._getWeek(b))
		}
	}, {
		key: '_getWeek',
		value: function _getWeek(b) {
			var c = this.getDate(b),
				e = c.fullDate,
				f = c.year,
				g = c.month,
				h = c.date,
				j = c.day,
				l = new Date(f, g - 1, 1).getDay(),
				n = new Date(f, g, 0).getDate(),
				o = {
					lastMonthDays: this._getLastMonthDays(l, this.getDate(b)),
					currentMonthDys: this._currentMonthDys(n, this.getDate(b)),
					nextMonthDays: [],
					weeks: []
				},
				p = [],
				q = 42 - (o.lastMonthDays.length + o.currentMonthDys.length);
			o.nextMonthDays = this._getNextMonthDays(q, this.getDate(b)), p = p.concat(o.lastMonthDays, o.currentMonthDys,
				o.nextMonthDays);
			for (var r = {}, s = 0; s < p.length; s++) 0 == s % 7 && (r[parseInt(s / 7)] = Array(7)), r[parseInt(s / 7)][s %
				7
			] = p[s];
			this.canlender = p, this.weeks = r
		}
	}]), a
}();
exports.default = Calendar;
